package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.trading.operate.parameter.resp.AcceptOrderResult;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;
import com.ymttest.utils.EnvSetup;

/**
 * BuyerSellerOrderStatistics
 * 
 *用户买手行为分析
 */
public class BuyerSellerOrderStatisticsMongoWapper {
	MongoDBDriver mdd;

	public BuyerSellerOrderStatisticsMongoWapper() throws Exception {
		mdd = new MongoDBDriver(EnvSetup.getSystemUrl("set5_mongoip"), Integer.valueOf(EnvSetup
				.getSystemUrl("set5_mongoport")), "Ymt_BuyerOrders");
		mdd.selectCollection("BuyerSellerOrderStatistics");		
		mdd.auth("buyerordersuser", "123456");	
		}

	/**
	 * 根据条件查询一条用户买手行为记录
	 * 
	 * @param id
	 * @return BuyerSellerOrderStatisticsMongoBean
	 * @throws Exception
	 */
	public ArrayList<BuyerSellerOrderStatisticsMongoBean> getBuyerSellerOrderStatistics(long id) throws Exception {
		String re = null;
        ArrayList<BuyerSellerOrderStatisticsMongoBean> buyerSellerOrderStatisticsList = new ArrayList<BuyerSellerOrderStatisticsMongoBean>();
		ArrayList<String> list = mdd.selectPart("{\"_id\":"+id+"}");		
		try {			
			re = list.toString();
			buyerSellerOrderStatisticsList =(ArrayList<BuyerSellerOrderStatisticsMongoBean>) FormatUtil.GSONToObject(re, new TypeToken<ArrayList<BuyerSellerOrderStatisticsMongoBean>>() {}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return buyerSellerOrderStatisticsList;
	}

	protected void close() throws Throwable {
		mdd.close();
	}
	
	public static void main(String args[])
	{
		try {
			List<BuyerSellerOrderStatisticsMongoBean> buyerSellerOrderStatisticsList =new BuyerSellerOrderStatisticsMongoWapper().getBuyerSellerOrderStatistics(86924550338711038l);
			
			Logger.debug("buyerSellerOrderStatisticsList:"+buyerSellerOrderStatisticsList);
			Logger.debug("buyerSellerOrderStatisticsList id:"+buyerSellerOrderStatisticsList.get(0).getAnyConfirmed());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
